package com.fdb.efp.nls.service.yed.common.rules.apply;

import com.fdb.basic.framework.core.constant.EsbRetCodeStandard;
import com.fdb.basic.framework.core.exception.BizException;
import com.fdb.basic.framework.core.util.DateUtility;
import com.fdb.efp.nls.service.yed.common.rules.CheckRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 需求编号:2019D08--
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2020/2/29
 * 功能描述:
 * 修改日期:2020/2/29
 * 修改描述:
 */
public class ApplyIsOverCreditApplyDateRule implements CheckRule {
    private static Logger logger = LoggerFactory.getLogger(ApplyIsOverCreditApplyDateRule.class);
    private String applyDate;
    private int loanTerm;
    private String loanDate;
    private String useCrdtAppSrlNo;

    public ApplyIsOverCreditApplyDateRule(String applyDate, int loanTerm, String loanDate, String useCrdtAppSrlNo) {
        this.applyDate = applyDate;
        this.loanTerm = loanTerm;
        this.loanDate = loanDate;
        this.useCrdtAppSrlNo = useCrdtAppSrlNo;
    }

    @Override
    public void check() throws BizException {
        if (DateUtility.compareToDate(
                DateUtility.ADD_MONTH(applyDate, 12),
                DateUtility.ADD_MONTH(loanDate, loanTerm)) < 0) {
            if (logger.isErrorEnabled()) {
                logger.error("普税贷用信通知接口 用信申请流水号:【"+useCrdtAppSrlNo+"】 贷款期限超过授信有效期！");
            }
            throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "用信申请流水号： + 【" + useCrdtAppSrlNo + "】 + ，贷款期限超过授信有效期！");
        }
    }
}
